home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / ipscan.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  2KB  |  72 lines

  1. /* IP Scan Version 1.1
  2.  * Coded by RooK
  3.  * Contact Information: rook@forfree.at
  4.  *                      http://www2.fwi.com/~rook/
  5.  *
  6.  * This is a simple to use and basic port scanner for Unix.
  7.  * To compile:
  8.  *             gcc -s ipscan.c -o ipscan
  9.  */
  10.  
  11.  
  12. #include <stdio.h>
  13. #include <sys/socket.h>
  14. #include <netinet/in.h>
  15. #include <errno.h>
  16. #include <netdb.h>
  17. #include <signal.h>
  18.  
  19. #define VERSION "Version 1.1"
  20.  
  21. int main(int argc, char **argv)
  22. {
  23.   int probeport = 0;
  24.   struct hostent *host;
  25.   int err, i, net;
  26.   struct sockaddr_in sa;
  27.  
  28.   
  29.   printf("--==[ IP Scan %s ]==--\n", VERSION);
  30.   printf("            by RooK\n\n");
  31.  
  32.   if (argc != 2) {
  33.     printf("Usage: %s IP Address\n", argv[0]);
  34.     exit(1);
  35.   }
  36.  
  37.   for (i = 1; i < 10001; i++) {
  38.     strncpy((char *)&sa, "", sizeof sa);
  39.     sa.sin_family = AF_INET;
  40.     if (isdigit(*argv[1]))
  41.       sa.sin_addr.s_addr = inet_addr(argv[1]);
  42.     else if ((host = gethostbyname(argv[1])) != 0)
  43.       strncpy((char *)&sa.sin_addr, (char *)host->h_addr, sizeof sa.sin_addr);
  44.     else {
  45.       herror(argv[1]);
  46.       exit(2);
  47.     }
  48.     sa.sin_port = htons(i);
  49.     net = socket(AF_INET, SOCK_STREAM, 0);
  50.     if (net < 0) {
  51.       perror("\nsocket");
  52.       exit(2);
  53.     }
  54.     err = connect(net, (struct sockaddr *) &sa, sizeof sa);
  55.     if (err < 0) {
  56.       printf("IP: %s    Port: %-5d %s\r", argv[1], i, strerror(errno));
  57.       fflush(stdout);
  58.     } else {
  59.       printf("IP: %s    Port: %-5d OPEN.              \n", argv[1], i);
  60.       if (shutdown(net, 2) < 0) {
  61.     perror("\nshutdown");
  62.     exit(2);
  63.       }
  64.     }
  65.     close(net);
  66.   }
  67.   printf("                                                                \r");
  68.   fflush(stdout);
  69.   return (0);
  70. }
  71.  
  72.